﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Server;
using NetBay.Core.BusinessEntities.AdvancedSearchCriteria;
using NetBay.Core.BusinessEntities.Resources;

#endregion

namespace NetBay.Core.BusinessEntities
{
    /// <summary>
    /// DATABASE TABLENAME : r_paramtd
    /// </summary>
    [DataContract]
    public class FolderType : ReturnObject
    {
        #region Enums
        #endregion

        #region Constants
        #endregion

        #region Private members
        /// <summary>
        /// Docume,t folder identifier
        /// </summary>
        private long m_lIdentifier;

        /// <summary>
        /// the parent organization identifier
        /// </summary>
        private long m_lOrganizationIdentifier;

        /// <summary>
        /// The name of tje document folder
        /// </summary>
        private string m_sName;

        /// <summary>
        /// The name of the Table where
        /// </summary>
        private string m_sTable;

        /// <summary>
        /// A label
        /// </summary>
        private string m_sLabel;

        /// <summary>
        /// The rank of the document folder
        /// </summary>
        private int m_iRank;

        /// <summary>
        /// 
        /// </summary>
        private int m_iNumberOfIndex;

        /// <summary>
        /// Indicate whether the folder type is deleted (rp_td_suppr)
        /// </summary>
        private bool m_bDeleted;

        /// <summary>
        /// 
        /// </summary>
        private List<Index> m_lstIndex = new List<Index>();

        /// <summary>
        /// 
        /// </summary>
        private List<Cart> m_lstCart = new List<Cart>();

        /// <summary>
        /// 
        /// </summary>
        private List<Folder> m_lstFolders = new List<Folder>();

        /// <summary>
        /// 
        /// </summary>
        private List<Folder> m_lstFoldersInternal = new List<Folder>();

        private List<Group> _lstGroups = new List<Group>();

        /// <summary>
        /// 
        /// </summary>
        private List<Item> m_lstItems = new List<Item>();

        /// <summary>
        /// Represents the tree node for items
        /// </summary>
        private string m_aTreeNodeForItem;
        #endregion

        #region Properties
        [Association("LstFolders", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<Folder> LstFolders
        {
            get { return m_lstFolders; }
            set
            {
                m_lstFolders = value;
                ItemEntity.SetForeignKey(m_lstFolders, Key);
            }
        }

        public List<Folder> LstFoldersInternal
        {
            get { return m_lstFoldersInternal; }
            set { m_lstFoldersInternal = value; }
        }

        [Association("LstItems", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<Item> LstItems
        {
            get { return m_lstItems; }
            set
            {
                m_lstItems = value;
                ItemEntity.SetForeignKey(m_lstItems, Key);
            }
        }

        [Association("CartList", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<Cart> CartList
        {
            get { return m_lstCart; }
            set
            {
                m_lstCart = value;
                ItemEntity.SetForeignKey(m_lstCart, Key);
            }
        }

        /// <summary>
        /// Gets or sets the attached groups.
        /// </summary>
        /// <value>
        /// The attached groups.
        /// </value>
        [Association("LstGroup", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<Group> AttachedGroups
        {
            get { return _lstGroups; }
            set
            {
                _lstGroups = value;
                ItemEntity.SetForeignKey(_lstGroups, Key);
            }
        }

        [DataMember]
        public int Rank
        {
            get { return m_iRank; }
            set { m_iRank = value; }
        }

        [DataMember]
        public int NumberOfIndex
        {
            get { return m_iNumberOfIndex; }
            set { m_iNumberOfIndex = value; }
        }

        [Association("LstIndex", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<Index> LstIndex
        {
            get { return m_lstIndex; }
            set
            {
                m_lstIndex = value;
                ItemEntity.SetForeignKey(m_lstIndex, Key);
            }
        }

        [DataMember]
        public string Name
        {
            get { return m_sName; }
            set { m_sName = value; }
        }

        [DataMember]
        public long Identifier
        {
            get { return m_lIdentifier; }
            set { m_lIdentifier = value; }
        }

        [DataMember]
        public string Table
        {
            get { return m_sTable; }
            set { m_sTable = value; }
        }


        /// <summary>
        /// Gets or sets the label.
        /// </summary>
        /// <value>
        /// The label.
        /// </value>
        [Required(ErrorMessageResourceType = typeof(Global), ErrorMessageResourceName = "NameRequired")]
        [StringLength(45, ErrorMessageResourceType = typeof(Global), ErrorMessageResourceName = "StringLength")]
        [DataMember]
        public string Label { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        [StringLength(256, ErrorMessageResourceType = typeof(Global), ErrorMessageResourceName = "StringLength")]
        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public long OrganizationIdentifier
        {
            get { return m_lOrganizationIdentifier; }
            set { m_lOrganizationIdentifier = value; }
        }

        /// <summary>
        /// Represents the tree node for items
        /// </summary>
        [DataMember]
        public string TreeNodeForItem
        {
            get { return m_aTreeNodeForItem; }
            set { m_aTreeNodeForItem = value; }
        }

        /// <summary>
        /// Indicate whether the folder type is deleted (rp_td_suppr)
        /// </summary>
        [DataMember]
        public bool Delete
        {
            get { return this.m_bDeleted; }
            set { this.m_bDeleted = value; }
        }
        #endregion

        #region ToString
        /// <summary>
        /// Extend default description of class
        /// </summary>
        /// <returns>description of instance</returns>
        public override string ToString()
        {
            StringBuilder parameters = new StringBuilder("Identifier<", 4096);
            parameters.Append(Identifier); parameters.Append("> ");
            parameters.Append("Label<"); parameters.Append(Label); parameters.Append("> ");
            parameters.Append("Table<"); parameters.Append(Table); parameters.Append("> ");

            return parameters.ToString();
        }
        #endregion

        #region Init/Constructor
        /// <summary>
        /// Default constructor
        /// </summary>
        public FolderType()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FolderType"/> class for error usages
        /// </summary>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="applicationException">The application exception.</param>
        public FolderType(string errorMessage, Exception applicationException = null)
            : base(errorMessage, applicationException)
        {
        }
        #endregion


        public override object Clone()
        {
            throw new NotImplementedException();
        }
    }

    public abstract class FolderTypeDer : FolderType
    {
        public abstract void SetIndexList();
        public abstract void SetIndexList(long p_lUserId);
        public abstract void SetFolderList(long p_lUserId, Dictionary<long, string> p_oCriteriaFilter);
        public abstract void SetFolderList(long p_lUserId, List<AdvancedSearchCriteriaItem> p_oCriteriaFilter);
        public abstract void SetItemList(long p_lUserId);
        public abstract void SetGroupList();
    }
}
